Trò chơi đua xe động vật trong UNITY Engine
114.675 lượt xem;
- InterpolationProcess.cs
- Interpolations /
- Bapk /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 public abstract class InterpolationProcess {
5 public abstract float apply(float a);
6
7 public float apply(float start, float end, float a)
8 {
9 return start + (end - start) * apply(a);
10 }
11
12 public static InterpolationProcess createInterpolation(Interpolation interpolation)
13 {
14 InterpolationProcess process = null;
15 switch (interpolation)
16 {
17 case Interpolation.pow2:
18 process = new InterpolationPow(2);
19 break;
20 case Interpolation.pow3:
21 process = new InterpolationPow(3);
22 break;
23 case Interpolation.pow4:
24 process = new InterpolationPow(4);
25 break;
26 case Interpolation.pow5:
27 process = new InterpolationPow(5);
28 break;
29 case Interpolation.powIn2:
30 process = new InterpolationPowIn(2);
31 break;
32 case Interpolation.powIn3:
33 process = new InterpolationPowIn(3);
34 break;
35 case Interpolation.powIn4:
36 process = new InterpolationPowIn(4);
37 break;
38 case Interpolation.powIn5:
39 process = new InterpolationPowIn(5);
40 break;
41 case Interpolation.powOut2:
42 process = new InterpolationPowOut(2);
43 break;
44 case Interpolation.powOut3:
45 process = new InterpolationPowOut(3);
46 break;
47 case Interpolation.powOut4:
48 process = new InterpolationPowOut(4);
49 break;
50 case Interpolation.powOut5:
51 process = new InterpolationPowOut(5);
52 break;
53 case Interpolation.sine:
54 process = new InterpolationSine();
55 break;
56 case Interpolation.sineIn:
57 process = new InterpolationSineIn();
58 break;
59 case Interpolation.sineOut:
60 process = new InterpolationSineOut();
61 break;
62 case Interpolation.exp10:
63 process = new InterpolationExp(2, 10);
64 break;
65 case Interpolation.exp10In:
66 process = new InterpolationExpIn(2, 10);
67 break;
68 case Interpolation.exp10Out:
69 process = new InterpolationExpOut(2, 10);
70 break;
71 case Interpolation.exp5:
72 process = new InterpolationExp(2, 5);
73 break;
74 case Interpolation.exp5In:
75 process = new InterpolationExpIn(2, 5);
76 break;
77 case Interpolation.exp5Out:
78 process = new InterpolationExpOut(2, 5);
79 break;
80 case Interpolation.elastic:
81 process = new InterpolationElastic(2, 10);
82 break;
83 case Interpolation.elasticIn:
84 process = new InterpolationElasticIn(2, 10);
85 break;
86 case Interpolation.elasticOut:
87 process = new InterpolationElasticOut(2, 10);
88 break;
89 case Interpolation.swing:
90 process = new InterpolationSwing(1.5f);
91 break;
92 case Interpolation.swingIn:
93 process = new InterpolationSwingIn(2);
94 break;
95 case Interpolation.swingOut:
96 process = new InterpolationSwingOut(2);
97 break;
98 case Interpolation.bounce:
99 process = new InterpolationBounce(4);
100 break;
101 case Interpolation.bounceIn:
102 process = new InterpolationBounceIn(4);
103 break;
104 case Interpolation.bounceOut:
105 process = new InterpolationBounceOut(4);
106 break;
107 case Interpolation.fade:
108 process = new InterpolationFade();
109 break;
110 }
111 return process;
112 }
113 }
2 using System.Collections;
3
4 public abstract class InterpolationProcess {
5 public abstract float apply(float a);
6
7 public float apply(float start, float end, float a)
8 {
9 return start + (end - start) * apply(a);
10 }
11
12 public static InterpolationProcess createInterpolation(Interpolation interpolation)
13 {
14 InterpolationProcess process = null;
15 switch (interpolation)
16 {
17 case Interpolation.pow2:
18 process = new InterpolationPow(2);
19 break;
20 case Interpolation.pow3:
21 process = new InterpolationPow(3);
22 break;
23 case Interpolation.pow4:
24 process = new InterpolationPow(4);
25 break;
26 case Interpolation.pow5:
27 process = new InterpolationPow(5);
28 break;
29 case Interpolation.powIn2:
30 process = new InterpolationPowIn(2);
31 break;
32 case Interpolation.powIn3:
33 process = new InterpolationPowIn(3);
34 break;
35 case Interpolation.powIn4:
36 process = new InterpolationPowIn(4);
37 break;
38 case Interpolation.powIn5:
39 process = new InterpolationPowIn(5);
40 break;
41 case Interpolation.powOut2:
42 process = new InterpolationPowOut(2);
43 break;
44 case Interpolation.powOut3:
45 process = new InterpolationPowOut(3);
46 break;
47 case Interpolation.powOut4:
48 process = new InterpolationPowOut(4);
49 break;
50 case Interpolation.powOut5:
51 process = new InterpolationPowOut(5);
52 break;
53 case Interpolation.sine:
54 process = new InterpolationSine();
55 break;
56 case Interpolation.sineIn:
57 process = new InterpolationSineIn();
58 break;
59 case Interpolation.sineOut:
60 process = new InterpolationSineOut();
61 break;
62 case Interpolation.exp10:
63 process = new InterpolationExp(2, 10);
64 break;
65 case Interpolation.exp10In:
66 process = new InterpolationExpIn(2, 10);
67 break;
68 case Interpolation.exp10Out:
69 process = new InterpolationExpOut(2, 10);
70 break;
71 case Interpolation.exp5:
72 process = new InterpolationExp(2, 5);
73 break;
74 case Interpolation.exp5In:
75 process = new InterpolationExpIn(2, 5);
76 break;
77 case Interpolation.exp5Out:
78 process = new InterpolationExpOut(2, 5);
79 break;
80 case Interpolation.elastic:
81 process = new InterpolationElastic(2, 10);
82 break;
83 case Interpolation.elasticIn:
84 process = new InterpolationElasticIn(2, 10);
85 break;
86 case Interpolation.elasticOut:
87 process = new InterpolationElasticOut(2, 10);
88 break;
89 case Interpolation.swing:
90 process = new InterpolationSwing(1.5f);
91 break;
92 case Interpolation.swingIn:
93 process = new InterpolationSwingIn(2);
94 break;
95 case Interpolation.swingOut:
96 process = new InterpolationSwingOut(2);
97 break;
98 case Interpolation.bounce:
99 process = new InterpolationBounce(4);
100 break;
101 case Interpolation.bounceIn:
102 process = new InterpolationBounceIn(4);
103 break;
104 case Interpolation.bounceOut:
105 process = new InterpolationBounceOut(4);
106 break;
107 case Interpolation.fade:
108 process = new InterpolationFade();
109 break;
110 }
111 return process;
112 }
113 }